/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package management;

import entity.Menu;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class ManagerMenu {

    public static String sqlTbl_Menu = "select Menu_Id, Menu, MenuItem, Menu_Price from Menu ";
    public static String sqlTbl_Menu2 = "select Menu_Id, Menu, MenuItem, Menu_Price from Menu ";
    public static boolean addMenu(Menu menu) {
        try {
            PreparedStatement ps;
            String sql = "insert into Menu values('" + menu.getDayOfWeek() + "','" + menu.getMenu() + "','"+menu.getMenuItem()+"','"+menu.getMenu_Price()+"')";
            ps = MyConnection.getConnection().prepareStatement(sql);
            ps.executeUpdate();
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }

    public static boolean updateMenu(Menu menu) {
        String sql = "update Menu set  DayofWeek = '" + menu.getDayOfWeek() + "', Menu= '" + menu.getMenu() + "', MenuItem ='"+menu.getMenuItem()+"',Menu_Price = '"+menu.getMenu_Price()+"' where  Menu_Id= '" + menu.getMenu_Id() + "'";
        try {
            PreparedStatement ps = null;
            ps = MyConnection.getConnection().prepareStatement(sql);
            ps.executeUpdate();
            return true;
        } catch (SQLException ex) {
            ex.printStackTrace();
            return false;
        }
    }

    public static void deleteMenu(int id_menu) {
        String sql = "delete from Menu where Menu_Id ='" + id_menu + "'";
        Statement st;
        try {
            st = MyConnection.getConnection().createStatement();
            st.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Delete Menu successful!");
        } catch (SQLException ex) {
//            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Delete Menu type error!");
        }
    }

//    public static Menu searchMenu(String nameProduct) {
//        String sql = "select * from Menu where Product_Name = ?";
//        try {
//            PreparedStatement ps = MyConnection.getConnection().prepareStatement(sql);
//            ps.setString(1, nameProduct);
//            ResultSet rs = ps.executeQuery();
//
//            if (rs.next()) {
//                Menu menu = new Menu();
//                menu.setProduct_Name(rs.getString("Product_Name"));
//                menu.setProduct_price(rs.getDouble("Product_price"));
//                return menu;
//            }
//        } catch (SQLException ex) {
//            ex.printStackTrace();
//        }
//        return null;
//    }
}
